package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class Test4 {
    public static void main(String[] args) throws Exception {
        Class clas = Class.forName("reflect.Person");
        Constructor c = clas.getConstructor(String.class);
        Object obj = c.newInstance("李四");
        Method[] method = clas.getDeclaredMethods();
        for (Method m :method){
            if (m.isAnnotationPresent(AutoRunMethod.class)){
                System.out.println(m.getName()+"()方法被标注了");
                AutoRunMethod a = m.getAnnotation(AutoRunMethod.class);
                int n = a.value();
                System.out.println("调用方法:"+n+"次");
                for (int i = 0;i<n; i++){
                    m.invoke(obj);
                }
            }else {
                System.out.println(m.getName()+"()方法没有被标注");
            }
        }

    }
}
